package generator.equation;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

public class Entropy {
	
	HashMap<String, Integer> Distribution = new HashMap<String, Integer>();
	long Rows;
	double result = 0;
	
	public Entropy(HashMap<String,Integer> Distribute, long rows){
		
		Distribution = Distribute;
		Rows = rows;
		
	}
	
	public double getResult(){
		
		Arith compute = new Arith();
		Set<String> value = Distribution.keySet();
		for(Iterator<String> ite = value.iterator(); ite.hasNext();){
			long distri = Distribution.get(ite.next());
			double prob = compute.div(distri, Rows);
			result += prob * Math.log(prob);
		}
		
		result = 0 - result;
		
		return result;
		
	}
	
}
